package com.dinzeer.legendreliclib.lib.compat.slashblade;

import mods.flammpfeil.slashblade.SlashBlade;
import mods.flammpfeil.slashblade.registry.slashblade.SlashBladeDefinition;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;

public class SlashBladeCreativeTap {
    public static void fillBladesForNamespace(CreativeModeTab.ItemDisplayParameters features, CreativeModeTab.Output output, String namespace) {
        if (Minecraft.getInstance().getConnection() != null) {
            SlashBlade.getSlashBladeDefinitionRegistry(features.holders())
                    .listElements().sorted(SlashBladeDefinition.COMPARATOR)
                    .filter(entry -> {
                        ResourceLocation loc = ResourceLocation.tryParse(entry.value().getName().getNamespace());
                        return loc != null && entry.value().getName().getNamespace().equals(namespace);
                    })
                    .forEach((entry) -> {
                        if (!((SlashBladeDefinition)entry.value()).getBlade().isEmpty()) {
                            output.accept(((SlashBladeDefinition)entry.value()).getBlade());
                        }

                    });
        }
    }

}
